#include <iostream>
#include "Hero.h"

Hero::Hero(int h, int a, int d):basic_HP(h), basic_AD(a), basic_Defense(d), HP(h), max_HP(h){
	for(int i =0 ; i < 6; i++){
		items[i] = NULL;
	}
	itemCount = 0;
}

Hero::~Hero(){
	for(int i = 0; i < 6; i++){
		if(items[i]){
			delete items[i];
		}
	}
}

void Hero::addItem(Item* item) {
    if ( item == NULL ) return ;
    if ( itemCount < 6 ) {
        items[itemCount] = item;
        itemCount ++ ;

        HP += item->gainHP();
        
    }
}

string Hero::getName() const{
    return this -> _name;
}

int Hero::getHP() const{
	return HP;
}

int Hero::getMaxHP() const {
    int result_max_HP = max_HP;
    for (int i = 0 ; i < itemCount ; ++i) {
        result_max_HP += items[i]->gainHP();
    }
    return result_max_HP;
}

void Hero::decreaseHP(int quant){
	HP -= quant;
}


void Hero::increaseDefense(int quant){
	basic_Defense += quant;
}

void Hero::increaseAD(int quant){
	basic_AD += quant;
}

double Hero::getAD() const {
    double result_ad = basic_AD;

    for ( int i = 0; i < itemCount ; ++i ){
        result_ad += items[i] -> gainAD();
    }

    return result_ad;
}

double Hero::getDefense() const {
    double result_defense = basic_Defense;

    for ( int i=0 ; i < itemCount ; ++i ) {
        result_defense += items[i] -> gainDefense();
    }

    return result_defense;

}

void Hero::action() {
}
